﻿using System;
using Xunit;

namespace LeRenard.Core.Tests._utils_
{
    public class ToStringHelperTests
    {
        [Fact]
        public void For_Returns_ToString_Correct_Value()
        {
            // Arrange
            var input = 50;
            var expected = input.ToString();

            // Act
            var actual = ToStringHelper.For(input);

            // Assert
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void For_Returns_Null_String_Constant_When_Input_Object_Is_Null()
        {
            // Arrange
            var input = (object)null;
            var expected = ToStringHelper.NULL_STRING;

            // Act
            var actual = ToStringHelper.For(input);

            // Assert
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void For_Selector_Returns_Correct_Value()
        {
            // Arrange
            var input = DateTime.UtcNow;
            var expected = input.ToShortDateString();

            // Act
            var actual = ToStringHelper.For(input, d => d.ToShortDateString());

            // Assert
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void For_Selector_Return_Exception_String_Constant_When_Selector_Causes_Exception()
        {
            // Arrange
            var input = String.Empty;
            var expected = ToStringHelper.EXCEPTION_STRING.FormatWith(
                    typeof(IndexOutOfRangeException).Name
                );

            // Act
            var actual = ToStringHelper.For(input, s => s[5].ToString());

            // Assert
            Assert.Equal(expected, actual);
        }
    }
}
